package com.runvp.rest.biz;

import com.runvp.common.annotation.Log;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.core.page.TableDataInfo;
import com.runvp.common.enums.BusinessType;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.service.biz.domain.BizOrderRealTimeData;
import com.runvp.service.biz.service.IBizOrderRealTimeDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单充电实时数据Controller
 * 
 * @author runvp
 * @date 2024-07-15
 */
@Controller
@RequestMapping("/biz/realtimedata")
public class BizOrderRealTimeDataController extends BaseController {
    private String prefix = "biz/realtimedata";

    @Autowired
    private IBizOrderRealTimeDataService bizOrderRealTimeDataService;

    @RequiresPermissions("biz:realtimedata:view")
    @GetMapping()
    public String realtimedata(ModelMap mmap,String orderNo) {
        mmap.put("orderNo", orderNo);
        return prefix + "/realtimedata";
    }

    /**
     * 查询订单充电实时数据列表
     */
    @RequiresPermissions("biz:realtimedata:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizOrderRealTimeData bizOrderRealTimeData) {
        startPage();
        List<BizOrderRealTimeData> list = bizOrderRealTimeDataService.selectBizOrderRealTimeDataList(bizOrderRealTimeData);
        return getDataTable(list);
    }

    /**
     * 导出订单充电实时数据列表
     */
    @RequiresPermissions("biz:realtimedata:export")
    @Log(title = "订单充电实时数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizOrderRealTimeData bizOrderRealTimeData) {
        List<BizOrderRealTimeData> list = bizOrderRealTimeDataService.selectBizOrderRealTimeDataList(bizOrderRealTimeData);
        ExcelUtil<BizOrderRealTimeData> util = new ExcelUtil<BizOrderRealTimeData>(BizOrderRealTimeData.class);
        return util.exportExcel(list, "订单充电实时数据数据");
    }

    /**
     * 新增订单充电实时数据
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存订单充电实时数据
     */
    @ParamValid
    @RequiresPermissions("biz:realtimedata:add")
    @Log(title = "订单充电实时数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizOrderRealTimeData bizOrderRealTimeData) {
        return toAjax(bizOrderRealTimeDataService.insertBizOrderRealTimeData(bizOrderRealTimeData));
    }

    /**
     * 修改订单充电实时数据
     */
    @RequiresPermissions("biz:realtimedata:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizOrderRealTimeData bizOrderRealTimeData = bizOrderRealTimeDataService.selectBizOrderRealTimeDataById(id);
        mmap.put("bizOrderRealTimeData", bizOrderRealTimeData);
        return prefix + "/edit";
    }
    /**
     * 订单充电实时数据详情
     */
    @RequiresPermissions("biz:realtimedata:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizOrderRealTimeData bizOrderRealTimeData = bizOrderRealTimeDataService.selectBizOrderRealTimeDataById(id);
        mmap.put("bizOrderRealTimeData", bizOrderRealTimeData);
        return prefix + "/detail";
    }
    /**
     * 修改保存订单充电实时数据
     */
    @ParamValid
    @RequiresPermissions("biz:realtimedata:edit")
    @Log(title = "订单充电实时数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizOrderRealTimeData bizOrderRealTimeData) {
        return toAjax(bizOrderRealTimeDataService.updateBizOrderRealTimeData(bizOrderRealTimeData));
    }

    /**
     * 删除订单充电实时数据
     */
    @RequiresPermissions("biz:realtimedata:remove")
    @Log(title = "订单充电实时数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizOrderRealTimeDataService.deleteBizOrderRealTimeDataByIds(ids));
    }
}
